
<template>
	<!-- 校区工作台 -->
	<div>
		<!-- 计划模板设置 -->
		<div>
			<el-row :gutter="10" style="margin-top:0.1rem;">
				<el-col :span="24" style="text-align:right;">
					<el-button @click="visibleTemplatePopup(true)">添加模板</el-button>
				</el-col>
			</el-row>
			<el-row style="margin-top:0.1rem;">
				<table class="table" cellspacing="0">
					<thead class="thead">
						<tr>
							<td style="width: 4rem;">模板名称</td>
							<td style="width: 4rem;">适用年级</td>
							<td style="width: 4rem;">使用期限</td>
							<td style="width: 4rem;">制表时间</td>
							<td style="width: 4rem;">制表人</td>
							<td style="width: 4rem;">状态</td>
							<td style="width: 4rem;">操作</td>
						</tr>
					</thead>
					<tbody class="tbody" v-if="plansetList&&plansetList.length>0">
						<tr v-for="(item,index) in plansetList" :key="index">
							<td>{{item.planTemplateName}}</td>
							<td>{{item._classNames}}</td>
							<td>{{item._date}}</td>
							<td>{{item.createTime}}</td>
							<td>{{item.createUserName}}</td>
							<td>{{item._enable}}</td>
							<td>
								<el-button v-if="item.isEnable==1" type="text" @click="activeTemplate(item,0)">禁用</el-button>
								<el-button v-else type="text" @click="activeTemplate(item,1)">启用</el-button>
								<el-button type="text" @click="queryTemplate(item)">查看</el-button>
								<el-button type="text" @click="deleteRow(item)">删除</el-button>
							</td>
						</tr>
					</tbody>
					<tbody class="tbody" v-else>
						<tr>
							<td colspan="7" align="center">该校区暂时没有设置模板</td>
						</tr>
					</tbody>
				</table>
			</el-row>
			<el-row>
				<el-pagination
					class="page"
					layout="total, sizes, prev, pager, next, jumper"
					:current-page="searchParam.currPage"
					@size-change="pageSizeChange"
					@current-change="curPageChange"
					:total="searchParam.total"
				></el-pagination>
			</el-row>
		</div>
		
		<el-dialog
		 :close-on-click-modal="false"
		 title="添加模板"
		 :visible.sync="addTemplatePopup.visible"
		 width="80%">
			<addTemplate ref="addTemplate" @cancle="visibleTemplatePopup(false)" @success="addTemplateCallback"></addTemplate>
		</el-dialog>
	</div>
</template>

<script>
	import addTemplate from './plan_add_template'
	let vm;
	export default{
		components:{addTemplate},
		data(){
			return {
				orgId:'',
				searchParam:{
					campusId:this.$store.state.campusId,
					currPage:1,
					pageSize:10,
					total:0
				},
				plansetList:[],
				addTemplatePopup:{
					visible:false,
				},
			}
		},
		methods:{
			init() {
				this.search(1);
			},
			campusChange : function(campusId) { //校区改变
				this.searchParam.campusId=campusId;
				this.init();
			},
			/**搜索 */
			search(pgIndex){
				this.searchParam.currPage=pgIndex||this.searchParam.currPage;
				api.teachPlanTemplateGetPage(this.searchParam)
				.then(function(data){
					if(data.resultCode==2000){
						vm.searchParam.total=data.totalCount;
						vm.plansetList=data.list;
						vm.plansetList.forEach(ele=>{
							ele._classNames='';
							ele.planTemplateGradeList.forEach(ele2=>{
								ele._classNames+=ele2.gradeTypeName+'、'
							});
							ele._classNames=ele._classNames.substr(0,ele._classNames.length-1);
							ele._date=ele.planStartTime.substr(5,5)+' 至 '+ele.planEndTime.substr(5,5);
							ele._enable=ele.isEnable==0?'未启用':'已启用';
						});
					}
					else{
						vm.$message({
							type:'warning',
							message:data.message
						})
					}
				});
			},
			pageSizeChange(val){
				this.searchParam.pageSize = val;
      			this.search(1);
			},
			curPageChange(val){
				this.search(val);
			},
			/**查看 */
			queryTemplate(data){
				api.teachPlanTemplateInfo({planTemplateId:data.planTemplateId})
				.then(function(data){
					if(data.resultCode==2000){
						vm.visibleTemplatePopup(true,0,data.info)
					}
					else{
						vm.$message({
							type:'warning',
							message:data.message
						})
					}
				})
			},
			/**启用、禁用
			 * @param isEnable 是否已启用 0-否，1-是
			 */
			activeTemplate(data,isEnable){
				api.teachPlanTemplateEnable({
					planTemplateId:data.planTemplateId,
					isEnable:isEnable
				})
				.then(function(data){
					if(data.resultCode==2000){
						let msg=isEnable==0?'禁用成功！':'启用成功';
						vm.$message({
							type:'success',
							message:msg
						});
						vm.search();
					}
					else{
						vm.$message({
							type:'warning',
							message:data.message
						})
					}
				})
			},
			/**删除行 */
			deleteRow(indata) {
				this.$confirm("此操作将删除该教学计划模板, 是否继续?", "温馨提示", {
					confirmButtonText: "确定",
					cancelButtonText: "取消",
					type: "warning",
					center: true
				})
				.then(() => {
					api.teachPlanTemplateDelete({planTemplateId:indata.planTemplateId})
					.then(function(data){
						if(data.resultCode==2000){
							vm.$message({
								type:'success',
								message:'删除成功！'
							})
							vm.search(1);
						}
						else{
							vm.$message({
								type:'warning',
								message:data.message||'操作失败'
							})
						}
					});
				})
				.catch(() => {});

				
			},
			addTemplateCallback(){
				this.search(1);
				this.visibleTemplatePopup(false);
			},
			/**新增查看弹窗 */
			visibleTemplatePopup(visible,isEdite=1,data=null){
				this.addTemplatePopup.visible=visible;
				if(visible){
					if(this.$refs['addTemplate']){
						this.$refs['addTemplate'].init({
							orgId:this.orgId,
							campusId:this.$store.state.campusId,
							isEdite:isEdite,
							data:data
						});
					}
					else{
						this.$nextTick(()=>{
							this.$refs['addTemplate'].init({
								orgId:this.orgId,
								campusId:this.$store.state.campusId,
								isEdite:isEdite,
								data:data
							});
						})
					}
				}
			}
		},
		mounted(){
			vm=this;
			let userInfo = tool.getItem(lsKey.user, true); //得到当前用户信息
			this.orgId=userInfo.orgId;
			this.init();
		},
		computed:{
			
		},
		watch:{

		}
	}
</script>

<style lang="scss" scoped>
	


	/*自定义滚动条样式*/
	// .box-tasks::-webkit-scrollbar {
	// 	// height: 0.08rem;
	// 	width: 0.05rem;
	// }
	// .box-tasks::-webkit-scrollbar-thumb {
	// 	border-radius: 0.5rem;
	// 	background: #BBBBBB;
	// }
	// .box-tasks::-webkit-scrollbar-track {
	// 	background: rgba(242, 246, 252, 0);
	// }	

	
</style>
<style scoped src="@/style/module/table.css"></style>